package com.liuyang.demo.threadPool;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.*;

@Slf4j
public class ThreadPoolDemoA {
    public static void main(String[] args) {

        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("automate-service-order-%d").build();
        ExecutorService THREAD_POOL = new ThreadPoolExecutor(10, 20, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(30000), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());

        List<Person> people = Arrays.asList(new Person[]{new Person("一", 0), new Person("二", 1), new Person("三", 2), new Person("四", 3), new Person("五", 4)});
        THREAD_POOL.execute(() -> {
            people.parallelStream().forEach(f -> {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                f.setName(f.getName() + f.getAge());
                f.setAge(f.getAge() + 1);

                log.info("{}",f);
            });
        });

        log.info("一：{}",people);

        try {
            Thread.sleep(900);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("二：{}",people);

        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("三：{}",people);

    }
}
